package com.example.cinema.adapter;

import android.content.Context;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.example.cinema.BR;
import com.example.cinema.CountListHeight;
import com.example.cinema.R;
import com.example.cinema.bindingdata.CircleItemData;
import com.example.cinema.drawview.CollapseText;

import java.util.List;
import java.util.logging.Handler;

//回帖适配器
public class ReplyListAdapter extends BaseAdapter {

    private int Layouid;
    private List<CircleItemData> dataList;
    private LayoutInflater inflater;
    private ListView listView;
    public ReplyListAdapter(Context context, int layouid, List<CircleItemData> dataList,ListView listView) {
        this.Layouid = layouid;
        this.dataList = dataList;
        this.inflater = LayoutInflater.from(context);
        this.listView = listView;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private ViewDataBinding dataBinding;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null)
        {
            dataBinding = DataBindingUtil.inflate(inflater,Layouid,parent,false);
            convertView = dataBinding.getRoot();
        }else {
            convertView = dataBinding.getRoot();
        }
        CollapseText collapse =  convertView.findViewById(R.id.collapse);
        collapse.setHeightLintener(new CollapseText.heightlintener() {
            @Override
            public void heightvariety(int height) {
                if(collapseText!=null)
                {
                    collapseText.onCollapseClick(height);
                }
            }
        });

        dataBinding.setVariable(BR.circledata,dataList.get(position));
        return convertView;
    }


    public  interface ReplyCollapseText{
        void onCollapseClick(int height);
    }
    private ReplyCollapseText collapseText;
    public void setOnReplyCollapseTextLintener(ReplyCollapseText collapseText)
    {
        this.collapseText = collapseText;
    }
}
